//
//  ViewController.m
//  王宇先_20_网络数据请求
//
//  Created by 王宇先 on 16/4/6.
//  Copyright © 2016年 王宇先. All rights reserved.
//

#import "ViewController.h"
#import "NetworkHandle.h"
#import "CellOfTitle.h"
#import "model.h"
@interface ViewController ()<NetworkHandleDelegate,UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *arrOfModel;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self handleData];
}
- (void)handleData{
      [NetworkHandle networkWithURL:@"http://api.m.mtime.cn/News/NewsList.api?pageIndex=1" delegate:self];
    
    
}
-(void)didFinishComplement:(id)result{
    self.arrOfModel = [NSMutableArray array];
    NSArray *arr = [result objectForKey:@"newsList"];
    for (NSDictionary *dic in arr) {
        model *mode1 = [[model alloc]init];
        [mode1 setValuesForKeysWithDictionary:dic];
        
        [self.arrOfModel addObject:mode1];
        
    }
    
    [self.tableView reloadData];
}
#pragma mark - 协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.arrOfModel.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CellOfTitle *cell = [tableView dequeueReusableCellWithIdentifier:@"pool"];
    model *mode = [self.arrOfModel objectAtIndex:indexPath.row];
    [cell setValue:mode];
    
    
    return cell;
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
